from selenium import webdriver
import time
from unittest import TestCase
from auto_chrome import expt2
from selenium.webdriver.common.by import By

class TestCampus(TestCase):




    def testCampus1(self):
        username = "lisi"
        passwd = "123456"
        expect = "申请成功!请等待管理员审核"

        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        driver.find_element(By.ID, "username").send_keys(username)
        time.sleep(1)
        driver.find_element(By.ID, "password").send_keys(passwd)
        time.sleep(1)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        #金融工具
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)
        #安全校园贷
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)

        #借点小钱
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys("10000")
        time.sleep(1)

        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(10)
        time.sleep(1)
        #确定
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
        time.sleep(1)
        #再确认
        driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(0.5)
        result = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        time.sleep(2)

        # driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        time.sleep(2)
        driver.quit()
        self.assertEqual(expect,result)


    #登录银行端
    def testcampus2(self):
        username = "username"
        passwd = "123456"
        expect = expt2.expt1(expt2)+10000
        expect2 = "999900.00元"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("lisi")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        #金融工具
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)

        #安全校园贷
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)

        #借点小钱
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys('10000')
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys('10')
        time.sleep(1)

        #确定
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(1)
        driver.quit()

        #再确认



        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("admin")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        #网贷关丽丽
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[5]/a').click()
        time.sleep(1)
        #网贷神奇
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[5]/ul/li[1]/a').click()
        time.sleep(1)
        #审核通过
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[7]/button[1]').click()
        time.sleep(1)
        #弹窗确认
        ele1 = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(1)

        ele1 = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        driver.quit()
        time.sleep(1)

        result = expt2.expt1(expt2)

        driver.quit()
        self.assertEqual(expect,result)


    #没银行卡
    def testcampus3(self):
        username = "username"
        passwd = "123456"
        expect = "申请失败，请先绑定个人信息"
        expect2 = "999900.00元"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("wangwu")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(2)
        #金融工具
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)
        #安全校园贷
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)
        #借点小钱
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys("10000")
        time.sleep(1)
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(10)
        time.sleep(1)
        #确定
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
        time.sleep(1)
        #再确认
        ele1 = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        driver.quit()
        self.assertEqual(expect,result)

#大额
    def testcampus4(self):
        username = "username"
        passwd = "123456"
        expect = "申请失败"
        expect2 = "999900.00元"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("lisi")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        #金融工具
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)
        #安全校园贷
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)
        #借点小钱
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys("10000000000000")
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(10)
        time.sleep(1)
        #确定
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
        time.sleep(1)
        #再确认
        ele1 = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        driver.quit()
        self.assertEqual(expect,result)


    #100的整数倍
    def testcampus5(self):
        username = "username"
        passwd = "123456"
        expect = "申请成功!请等待管理员审核"
        expect2 = expt2.expt1(expt2)
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("lisi")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        #金融工具
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)
        #安全校园贷
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)
        #借点小钱
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys("12")
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(10)
        time.sleep(1)
        #确定
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
        time.sleep(1)
        #再确认
        ele1 = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(1)
        driver.quit()
        result = expt2.expt1(expt2)



        self.assertEqual(expect,result)

#借一百万年
    def testcampus6(self):
        username = "username"
        passwd = "123456"
        expect = "输入期限不合法！"
        expect2 = "999900.00元"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("lisi")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        #金融工具
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)
        #安全校园贷
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)
        #借点小钱
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys("12")
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys('1000000000')
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
        time.sleep(1)

        result = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/span').text
        time.sleep(1)

        driver.quit()
        self.assertEqual(expect,result)

#     #超期
    def testcampus7(self):
        username = "username"
        passwd = "123456"
        expect = "申请成功!请等待管理员审核"
        expect2 = "999900.00元"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "username").send_keys("lisi")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "password").send_keys("123456")
        time.sleep(1)
        ele1 = driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        #金融工具
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)
        #安全校园贷
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)
        #借点小钱
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys("12")
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys('9999')
        time.sleep(1)
        #确定
        ele1 = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
        time.sleep(1)
        #再确认
        ele1 = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        time.sleep(1)

        # ele1 = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        time.sleep(1)
        driver.quit()
        self.assertEqual(expect,result)

